package com.ruoyi.web.controller.glzz.example;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Collections;
import java.util.List;

import com.influxdb.annotations.Column;
import com.influxdb.annotations.Measurement;
import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApi;
import com.influxdb.client.WriteApiBlocking;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import com.influxdb.query.FluxTable;

public class InfluxDB2Example {
    public static void main(final String[] args) {

        // You can generate an API token from the "API Tokens Tab" in the UI
        String token = "XBq3Ri4i1gioB8owwOjK0NnG8M1kAc0SJNoxtxtcHAKSSdKfJilZwMT3YChVslAAR7_L4erJD4F6sWXVaziY5g==";
        String bucket = "dev";
        String org = "glzz";

        InfluxDBClient client = InfluxDBClientFactory.create("http://localserver:8086", token.toCharArray());
        Point point = Point
                .measurement("mem")
                .addTag("host", "host1")
                .addField("used_percent", 23.43234543)
                .time(LocalDateTime.now().toInstant(ZoneOffset.of("+8")), WritePrecision.NS);

        WriteApiBlocking writeApi = client.getWriteApiBlocking();
        writeApi.writePoint(bucket, org, point);

    }
}
